home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11593 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie needs help w/ARGV ARGC
  5. Date: 25 Mar 1996 12:16:25 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4j62qp$fnj@sparcserver.lrz-muenchen.de>
  9. References: <4j4ja1$dc3@mtinsc01-mgt.ops.worldnet.att.net>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. dslayer@worldnet.att.net (Raymond Joh) writes:
  13.  
  14. >I have spent three days attempting to determine why my command line
  15. >arguments  are failing...
  16.  
  17. >I am using MS Quick C 2.5
  18.  
  19. >I just want to be able to enter two file paths at the command line.
  20. >Here is my code: 
  21.  
  22. >#include <stdio.h>
  23. >#include <stdlib.h>
  24.  
  25.  
  26. >main(int argc, char *argv[],char *envp[])
  27.  
  28. 1) Implicit "int" can be avoided, and should be avoided imho.
  29. 2) Since you don't _need_ "envp", and since it makes this 
  30.    program less portable, I wonder why you use it. 
  31.  
  32. >{
  33. >FILE *ofp,*nfp;
  34. >char ch;
  35.  
  36. >gets(*argv);
  37.  
  38. What is this supposed to do? "*argv" could be the name of your
  39. program, and it is _not_ a string variable you should use in 
  40. your program. If you want to read a string as the first action of
  41. your program, why not replace this line with:
  42.  
  43.    char line[BIG_ENOUGH];
  44.  
  45.    fgets(line, sizeof line, stdin);
  46.  
  47.  
  48. >if (argc!=3)
  49. >  {
  50. >  printf("Enter: <source> <destination>\n");
  51. >  exit(1);
  52. >  }
  53.  
  54. >Code countinues but when I enter my command line input such as:
  55.  
  56. >A:\readme.txt  A:\newfile.txt
  57.  
  58. Let us assume that your program is called "cp". If you enter
  59. "cp readme.txt newfile.txt" at your shell prompt, main will
  60. be called with 
  61.  
  62.   argc: 3
  63.   argv: { "cp", "readme.txt", "newfile.txt", NULL }
  64.  
  65. in a lot of environments. The exact value of "argv[0]" and both
  66. the existence and contents of "argv[3]" might vary on your system.
  67.  
  68. Kurt
  69. --
  70. | Kurt Watzka                             Phone : +49-89-2180-6254
  71. | watzka@stat.uni-muenchen.de
  72. | ua302aa@sunmail.lrz-muenchen.de
  73.